import { ElMessage } from 'element-plus';

export const checkStatus = error => {
  console.log('status error ===>', error);
  const status = error.response.status;
  let errorMessage = '';
  switch (status) {
    case 400:
      errorMessage = '请求错误';
      break;
    case 401:
      errorMessage = '未授权，请登录';
      break;
    case 403:
      errorMessage = '拒绝访问';
      break;
    case 404:
      errorMessage = `请求资源不存在: ${error.response.config.url}`;
      break;
    case 408:
      errorMessage = '请求超时';
      break;
    case 500:
      errorMessage = '服务器内部错误';
      break;
    case 501:
      errorMessage = '服务未实现';
      break;
    case 502:
      errorMessage = '网关错误';
      break;
    case 503:
      errorMessage = '服务不可用';
      break;
    case 504:
      errorMessage = '网关超时';
      break;
    case 505:
      errorMessage = 'HTTP版本不受支持';
      break;
    default:
      break;
  }
  // 错误提示
  ElMessage.error(errorMessage);
  return Promise.reject(error);
};
